package com.example.sunny.utils

import android.content.Context
import android.graphics.Bitmap
import java.io.File
import java.io.FileOutputStream

object FileUtils {
    fun storeBitmap(bitmap: Bitmap, fileName:String,context: Context): File {
        val file = File(context.externalCacheDir, fileName)
        if (file.exists()){
            file.delete()
        }
        file.createNewFile()

        try {
            val os = FileOutputStream(file)
            bitmap.compress(Bitmap.CompressFormat.PNG,85,os)
            os.flush()
            os.close()
        }catch (e:Exception){
            e.printStackTrace()
        }
        return file
    }
}